import request from '@/utils/request.js'
const state = {
  navData:{},
	swiperList:[],
	couponsList:{},
	bannerList:{},
	advList:[],
	addressList:[],
	showItemData:[]
}
const mutations = {
  SET_NAVDATA(state,navData){
    state.navData = navData
  },
	SET_SWIPERLIST(state,swiptList){
		state.swiperList = swiptList
	},
	SET_COUPONSLIST(state,couponsList){
		state.couponsList = couponsList
	},
	SET_BANNERLIST(state,bannerList){
		state.bannerList = bannerList
	},
	SET_ADVLIST(state,advList){
		state.advList = advList
	},
	SET_ADDRESSLIST(state,addressList){
		state.addressList = addressList
	},
	SET_SHOWITEMDATA(state,showItemData){
		state.showItemData = showItemData
	}
}
const actions = {
  async getNavData({commit}){
    const result = await request('/getHeaderNavList')
    commit('SET_NAVDATA',result)
  },
	async getSwiptList({commit}){
	  const result = await request('/getIndexSwiperList')
	  commit('SET_SWIPERLIST',result)
	},
	async getCouponsList({commit}){
	  const result = await request('/getIndexNavList')
	  commit('SET_COUPONSLIST',result)
	},
	async getBannerList({commit}){
	  const result = await request('/getIndexBannerList')
	  commit('SET_BANNERLIST',result)
	},
	async getAdvList({commit}){
	  const result = await request('/getIndexAdv')
	  commit('SET_ADVLIST',result)
	},
	async getAddressList({commit}){
	  const result = await request('/getIndexAddressList')
	  commit('SET_ADDRESSLIST',result)
	},
	async getShowItemData({commit}){
	  const result = await request('/getIndexShowItem')
	  commit('SET_SHOWITEMDATA',result)
	},
}
const getters = {
  goodsList(state){
    return (state.bannerList || {}).goods || {}
  },
	details(state){
		 return (state.bannerList || {}).details || [][0]
	},
	goods(state){
		return (state.advList || []).goods || [][0]
	},
	config(state){
		return (state.advList || []).config || {}
	},
}

export default {
  namespaced:true,
  state,
  mutations,
  actions,
  getters
}